我們會在views底下建立library_menu.xml:
<odoo>
<menuitem id="menu_library" name="Library" />
</odoo>
再來就是之前使用 Odoo Online Demo有學到的,建立兩個安全性群組。
到security/library_security.xml
<odoo>
<data>
<!-- user 執行日常操作 -->
<record id="library_group_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="base.module_category_services_library "/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
</data>
<!-- manager 可以完全存取所有功能 -->
<record id="library_group_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id"
ref="base.module_category_services_library "/>
<field name="implied_ids"
eval="[(4, ref('library_group_user'))]"/>
<field name="users"
eval="[(4, ref('base.user_root')),
(4, ref('base.user_admin'))]"/>
<!-- 指派給odoo root 跟 admin -->
</record>
</odoo>
到models/init.py
from . import library_book
建立一個 models/library_book.py:
from odoo import fields, models
class Book(models.Model):
"""
Describes a Book catalogue.
"""
_name = "library.book"
_description = "Book"
name = fields.Char("Title", required=True)
isbn = fields.Char("ISBN")
active = fields.Boolean("Active?", default=True)
date_published = fields.Date()
image = fields.Binary("Cover")
publisher_id = fields.Many2one("res.partner", string="Publisher")
author_ids = fields.Many2many("res.partner", string="Authors")
Tips:
我們今天新增的檔案,odoo都還不知道,所以要去__manifest__.py宣告,找到data
"data": [
"security/library_security.xml",
"views/library_menu.xml",
"views/library_menu.xml",
],
還要記得更新 -u
(env15)$ odoo -c ~/work15/library.conf -d library -u library_app